<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
$ColumnType = 3;
if (!is_numeric($_GET['ID'])) {MsgBox (1,'ID参数出现非数字错误！','-1');}
$nDo = $db->SelectSQL("SELECT `DownloadRela`,`DownloadType`,`DownloadTitle`,`DownloadUrl`,`DownloadViews` FROM `" . $dbprefix . "download` WHERE `ID` = '" . $_GET['ID'] . "'");
if(count($nDo)==0){MsgBox (1,'不存在的资源！','-1');}
Html($nDo[0]);

if($_POST['Action'] == 'UpDate'){
	
	$DownloadUrl = $_POST['DownloadUrl'];
	$rng = false;
	if($_POST['DownloadType'] == '0' && !empty($_FILES['upDownloadUrl']['tmp_name'])){
		$up = new upload();
		$up->save_dir = '../uploadfile/Download/';
		$up->ispics = false;		
		$up->field_name = 'upDownloadUrl';
		if($up->perform()){
			$DownloadUrl = str_replace('../','',$up->URL);
		} else {
			//echo '文件上传失败。返回信息：' . $up->info;
			$rng = true;
		}		
	}	
	
	$SQL = "UPDATE `" . $dbprefix . "download` SET 
	`DownloadRela` = '" . $_POST['DownloadRela'] . "',
	`DownloadType` = '" . $_POST['DownloadType'] . "',
	`DownloadTitle` = '" . $_POST['DownloadTitle'] . "',
	`DownloadUrl` = '" . $DownloadUrl . "',
	`DownloadViews` = '" . $_POST['DownloadViews'] . "'
	WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1;";
	if($db->ExecuteSQL($SQL)){
		AdminLog(1,$Lang,'修改下载资源(ID:' . $_GET['ID'] . '),结果：操作成功！'); 
		if ($rng === true) MsgBox (1,'数据修改成功,附件上传失败，返回上传信息：' . $up->info,'DownloadUpDate.php?ID=' . $ID . '&Lang=' . $Lang);
		if($_POST['isHTML'] == 'yes'){
			MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=DownloadColumn");
		}	
		MsgBox (1,'下载资源修改成功！','DownloadManage.php?Lang=' . $Lang . '&page=' . $_GET['page'] . '&Rela=' . $_GET['Rela']);
	} else {
		AdminLog(1,$Lang,'修改下载资源(ID:' . $_GET['ID'] . '),结果：操作失败！'); 
		MsgBox (1,'操作失败，请检查您提交的数据是否正确！','-1');
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script language="javascript">
function Check() {
	if (document.form1.DownloadRela.value==""){
		alert("请选择下载类别！");
		document.form1.DownloadRela.focus();
		return false;
	}
	if (document.form1.DownloadTitle.value==""){
		alert("请填写资源标题！");
		document.form1.DownloadTitle.focus();
		return false;
	}
	if(document.form1.DownloadViews.value.match(/^[0-9]\d*$/)==null){ 
		alert("下载次数必须为数字！"); 
		document.form1.DownloadViews.focus(); 
		return false; 
	}
}
</script>	
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd">
	<td>&nbsp;</td>
	<td align="right">
		<input type="button" value="添加资源" onClick="javascript:location.href='DownloadAdd.php?Lang=<?php echo $Lang?>'">
		<input type="button" value="资源管理" onClick="javascript:location.href='DownloadManage.php?Lang=<?php echo $Lang?>'">		
		<input type="button" value="类别管理" onClick="javascript:location.href='DownloadColumnManage.php?Lang=<?php echo $Lang?>'">
	</td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
  <form action="DownloadUpDate.php?Lang=<?php echo $Lang?>&page=<?php echo $_GET['page']?>&Rela=<?php echo $_GET['Rela']?>&ID=<?php echo $_GET['ID']?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return Check()">
  <tr>
    <td colspan="3" align="center" class="Main_Title">修改下载资源<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td height="20" align="right">所属类别：</td>
    <td><select name="DownloadRela" id="DownloadRela">
<option value="">==请选择下载类别==</option>
<?php
$Rs = $db->SelectSQL("SELECT `ID`,`ColumnRela`,`ColumnName`,`ColumnLevel`,`ColumnTime`,`ColumnSort` FROM `" . $dbprefix . "column` WHERE ColumnType = $ColumnType && ColumnLang = $Lang;",2);
@$Rs = sdb::column_sort($Rs);
for ($i=0;$i<count($Rs);$i++ ) {
	Html($Rs[$i]);
	for ($x=1;$x<$Rs[$i][3];$x++){$Spaces .= '├┈┈';} //加与栏目级数相同的空格
	$Rs[$i][3] > 1 ? $Spaces = $Spaces . $Rs[$i][2] : $Spaces = $Rs[$i][2]; //一级栏目前不加空格符
	if($nDo[0][0] != $Rs[$i][1])
		echo '<option value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	else
		echo '<option  selected="selected" value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	unset($Spaces);
}
unset($Rs,$i,$x);
?>  		
</select>
    	<span class="red">*</span></td>
    <td><a href="DownloadColumnManage.php?Lang=<?php echo $Lang?>">修改下载分类</a></td>
  </tr>
  <tr class="odd">
  	<td height="20" align="right">资源类型：</td>
  	<td><input name="DownloadType" type="radio" id="radio" value="0" <?php if($nDo[0][1] == 0)echo 'checked="checked"';?> onclick="document.getElementById('up').style.display = 'block';" />
  		内部资源
  			<input type="radio" name="DownloadType" id="radio2" value="1" <?php if($nDo[0][1] == 1)echo 'checked="checked"';?> onclick="document.getElementById('up').style.display = 'none';" />
  			外部资源</td>
  	<td>外部资源可填写其它站点下载资源</td>
  	</tr>
  <tr class="odd">
  	<td height="20" align="right">资源标题：</td>
  	<td><input name="DownloadTitle" type="text" class="input2" id="DownloadTitle" maxlength="100" value="<?php echo $nDo[0][2]?>" />
  		<span class="red">*</span></td>
  	<td>下载文件标题</td>
  	</tr>
  <tr class="odd" id="up" <?php if($nDo[0][1] == 1) echo 'style="display:none;"';?>>
  	<td height="20" align="right">上传文件：</td>
  	<td><input name="upDownloadUrl" type="file" id="upDownloadUrl" size="35" /></td>
  	<td>不更换文件资源时不用上传</td>
  	</tr>
  <tr class="odd">
  	<td height="20" align="right">文件地址：</td>
  	<td>
  		<input name="DownloadUrl" type="text" id="DownloadUrl" size="50" maxlength="100" value="<?php echo $nDo[0][3]?>" />
  		<span class="red">*</span></td>
  	<td>外部资源时需填写文件下载地址,须以&quot;<span class="Igreen">http://</span>&quot;开头</td>
  	</tr>
  <tr class="odd">
  	<td height="30" align="right">下载次数：</td>
  	<td><input name="DownloadViews" type="text" id="DownloadViews" size="5" maxlength="9" value="<?php echo $nDo[0][4]?>" />
  		<span class="red">*</span></td>
  	<td>不建议修改</td>
  	</tr>
<?php if($WebStaticHTML == 1){?>
  <tr class="odd">
  	<td align="right">生成静态：</td>
  	<td><input name="isHTML" type="checkbox" id="isHTML" value="yes" checked="checked" />生成HTML</td>
  	<td colspan="2">提交后将同时生成与该下载相关的HTML静态文件</td>
  	</tr>
<?php }?>			
  <tr class="odd">
  	<td height="30" align="right">&nbsp;</td>
  	<td><input type="submit" name="button" id="button" value="提 交" class="submit" />
  		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  		<input name="Action" type="hidden" id="Action" value="UpDate" />  		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  		<input type="reset" name="button2" id="button2" value="重 置" class="submit" /></td>
  	<td>请确保文件上传成功并已返回文件地址后提交</td>
  	</tr>
  </form>
  </table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
注：1、本页资源上传只对上传文件后缀做判断，为了您的系统安全，尽量不要开通一般管理员的"<span class="Igreen">上传下载资源</span>"管理权限；<br />
　　2、当前允许上传的文件类型有：<span class="Igreen"><?php echo $ps['upload']['annex_type'];?></span>，文件上传类型及上传大小在 图片处理设置(商业版) 或 config/pics.php(免费版)文件中修改。<br />
　　3、文件过大时请采用FTP软件上传至服务器后填写文件地址(内、外部均可)，本页适用于上传10M以下的文件(视服务器及网络状况而定)；<br />
　　4、当前服务器上传限制：upload_max_filesize(<?php echo get_cfg_var("upload_max_filesize");?>)；post_max_size(<?php echo get_cfg_var("post_max_size");?>)。
</td>
	</tr>
</table>   
</body>
</html>
